package com.ticket.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ticket.entity.Team;
import com.ticket.service.ITeamService;
import com.ticket.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/teams")
public class TeamController {

    @Autowired
    private ITeamService teamService;

    @GetMapping("/list")
    public Result<Page<Team>> listTeams(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size) {
        Page<Team> teamPage = teamService.searchTeams(keyword, page, size);
        return Result.success(teamPage);
    }

    @GetMapping("/{id}")
    public Result<Team> getTeamById(@PathVariable Long id) {
        Team team = teamService.getById(id);
        if (team == null) {
            return Result.error("球队不存在");
        }
        return Result.success(team);
    }
} 